package com.mqzhang.demo.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import com.mqzhang.demo.entity.TbTest;

/**
 * 控制层
 * 
 * @author mq.zhang
 * @version V1.0 2016年9月9日
 */
@Controller
@RequestMapping(value = "/demo")
public class ClientController {
    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping(value = { "/doget2" })
    @ResponseBody
    public String doGet2(@RequestParam(name = "pageNum", required = false) String pageNum, HttpServletRequest request,
            HttpServletResponse response, Model model) {
        Map<String, Object> params = new HashMap<String, Object>(2);
        params.put("pageNum", pageNum);
        @SuppressWarnings("unchecked")
        List<TbTest> reponseEntity = restTemplate.postForObject(
                "http://localhost/maven-mybatis-demo-web/demo/hellojson.html?pageNum={pageNum}", null, List.class, params);
        if (reponseEntity != null) {
            return reponseEntity.toString();
        }
        return "{}";
    }
}
